package br.trainee.web.constraint.impl;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import br.trainee.web.constraint.service.Cep;

public class CepImpl implements ConstraintValidator<Cep, String> {
	
	private String mensagem;
	
	@Override
	public void initialize(Cep anotacao) {
		this.mensagem = anotacao.message();
	}

	@Override
	public boolean isValid(String valor, ConstraintValidatorContext context) {
		
		if(!valor.matches("[0-9]{2}\\.?[0-9]{3}\\-?[0-9]{3}")){
			
			return false;
		}
		
		return true;
	}

}
